package com.jyhz.model.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author:谢君臣
 * @Date:2021/6/14-10:45
 * @version:1.0
 * @function:
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    private Logger logger = LoggerFactory.getLogger("拦截器层日志");
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 查询token
//        String token = CookieUtils.getCookieValue(request, "LY_TOKEN");
        logger.info("自定义请求拦截器");
//        if (StringUtils.isBlank(token)) {
////            // 未登录,返回401
////            response.setStatus(HttpStatus.UNAUTHORIZED.value());
////            return false;
////        }
        // 有token，查询用户信息
//        try {
////            // 解析成功，证明已经登录
////            UserInfo user = JwtUtils.getInfoFromToken(token, jwtProperties.getPublicKey());
////            // 放入线程域
////            tl.set(user);
//            return true;
//        } catch (Exception e) {
//            // 抛出异常，证明未登录或超时,返回401
//            response.setStatus(HttpStatus.UNAUTHORIZED.value());
//            return false;
//        }
        return true;
    }
}
